package com.uft.model.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.uft.controller.ServerController;
import com.uft.model.entity.Audit;
@Repository
public class AuditDAO {
	@PersistenceContext private EntityManager em;
	private  static Logger  logger = Logger.getLogger(ServerController.class);
	 // Retrieves all the Profiles:
	   public List<Audit> getAllAudit(int startIndex, int pageSize) {
		   logger.debug("startIndex="+startIndex+" pageSize: "+pageSize);
	       TypedQuery<Audit> query = em.createQuery(
	           "SELECT a FROM Audit a ", Audit.class);
	       query.setFirstResult(startIndex);
	       query.setMaxResults(pageSize);
	       List<Audit> audits=query.getResultList();
	       logger.debug("Size: "+audits.size());
	       return audits;
	   }
	   @Transactional
		public void addAudit(Audit audit){
		   logger.debug("Adding new Audit: ");
		   em.persist(audit);
		   logger.debug("Audit: "+audit.toString());
		}
}
